package org.hongqi.common.senpec.file.fileInfo;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hongqi.common.senpec.base.mybatisplus.IBaseController;
import org.hongqi.common.senpec.base.sevlet.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Collection;

@RestController
@RequestMapping("/file/fileInfo")
@RequiredArgsConstructor
@Slf4j
public class FileInfoController implements IBaseController<FileInfo> {

    private final FileInfoService fileInfoService;

    @PostMapping("/uploadOne")
    public FileInfo upload(String keyword, MultipartFile file) {
        log.info("upload is running............");
        return fileInfoService.uploadOneFile(keyword, file);
    }

    @PostMapping("/appendOne")
    public FileInfo appendOne(String keyword, MultipartFile file) {
        log.info("append is running............");
        return fileInfoService.appendOneFile(keyword, file);
    }


    @PostMapping("/uploadMany")
    public FileInfo uploadMany(String keyword, MultipartFile[] file) {
        log.info("upload is running............");
        for (MultipartFile multipartFile : file) {
            System.out.println(multipartFile.getOriginalFilename());
        }
//        return fileInfoService.uploadOneFile(keyword, file);
        return null;
    }


    @Override
    public Result<FileInfo> save(FileInfo entity) {
        return null;
    }

    @Override
    public Result<?> removeById(Long id) {
        return fileInfoService.myRemoveById(id);
    }

    @Override
    public Result<FileInfo> updateById(FileInfo entity) {
        return null;
    }

    @Override
    public Result<FileInfo> getById(Long id) {
        return null;
    }

    @GetMapping("/listByKeyword/{keyword}")
    public Result<Collection<FileInfo>> listByKeyword(@PathVariable(name = "keyword") String keyword) {
        return fileInfoService.myListByKeyword(keyword);
    }

}
